package org.cypress.rtpack.common.runner;

import java.time.LocalDateTime;

import org.cypress.rtpack.service.MdbsSlv1Service;
import org.cypress.rtpack.service.CommMoniService;
import org.cypress.rtpack.service.SOEProcessorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;

@Order
@Slf4j
@Component
public class StartedUpRunner implements ApplicationRunner {

	@Autowired
	private ConfigurableApplicationContext context;

	@Autowired
	private MdbsSlv1Service mdbsSlv1Service;
	@Autowired
	private CommMoniService commMoniService;
	@Autowired
	private SOEProcessorService soeProcessorService;

	@Override
	public void run(ApplicationArguments args) {
		if (context.isActive()) {
			log.info(" __    ___   _      ___   _     ____ _____  ____ ");
			log.info("/ /`  / / \\ | |\\/| | |_) | |   | |_   | |  | |_  ");
			log.info("\\_\\_, \\_\\_/ |_|  | |_|   |_|__ |_|__  |_|  |_|__ ");
			log.info("                                                      ");
			log.info("rtpack started. current time: " + LocalDateTime.now());

			mdbsSlv1Service.startServer();
			soeProcessorService.startProcessing();
			commMoniService.startMonitor();  //主进程循环追加任务，线程池处理
		}
	}
}
